﻿using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using XbsWebAPI.Application;
using XbsWebAPI.Application.OrderFinance;
using XbsWebAPI.Application.QueryModel;
using XbsWebAPI.EntityFrameworkCore.Entities;
using XbsWebAPI.EntityFrameworkCore.Entities.Enums;
using XbsWebAPI.MainHost.ViewModels;

namespace XbsWebAPI.MainHost.Controllers
{
    /// <summary>
    /// 订单管理
    /// </summary>
    [ApiController]
    [Route("api/xbs_v1/[controller]")]
    public class OrderController : Controller
    {
        private readonly IOrderAppService _orderAppService;

        public OrderController(IOrderAppService orderAppService)
        {
            _orderAppService = orderAppService;
        }

        /// <summary>
        /// 初始化订单（后端开发专用，不要点！！！）
        /// </summary>
        /// <returns></returns>
        [HttpPost, Route("[action]")]
        public ResultDto<string> InitOrderTest()
        {
            return new ResultDto<string>();
        }

        /// <summary>
        /// 查询订单详情
        /// </summary>
        /// <param name="orderId"></param>
        /// <returns></returns>

        [HttpGet, Route("[action]")]
        public ResultDto<OrderDetailDto> FindOrderDetail(Guid orderId)
        {
            ResultDto<OrderDetailDto> result = _orderAppService.GetOrderById(orderId);
            return result;
        }

        /// <summary>
        /// 确认订单（确认后的订单可以办理入住）
        /// </summary>
        /// <param name="orderId"></param>
        /// <returns></returns>
        [HttpGet, Route("[action]")]
        public async Task<ResultDto<string>> ConfirmOrderDetail(Guid orderId)
        {
            var result = await _orderAppService.ConfirmOrderDetailAsync(orderId);
            return result;
        }


        /// <summary>
        /// 分页查询订房订单
        /// </summary>
        /// <param name="IsContinueToLive">是否续住</param>
        /// <param name="orderStatus">订单状态</param>
        /// <param name="houseTypeId">房型Id</param>
        /// <param name="data">姓名 电话 预订单号 模糊查询</param>
        /// <param name="orderTimeType">查询时间类型（预订类型、入住时间、离店时间）</param>
        /// <param name="orderTimeBegin">开始时间</param>
        /// <param name="orderTimeEnd">结束时间</param>
        /// <param name="pageNumber">第几页，默认1</param>
        /// <param name="pageSize"> 每页多少条，默认10</param>
        /// <returns></returns>
        [HttpGet, Route("[action]")]
        public ResultDto<PageListDto<ListOrderDetailDto>> FindOrderPagedList(bool? IsContinueToLive, 
            OrderStatus? orderStatus,Guid? houseTypeId,string data, 
            OrderTimeType orderTimeType, DateTime? orderTimeBegin,DateTime? orderTimeEnd,
            int? pageNumber,int? pageSize)
        {
            QueryOrderDetail query = new QueryOrderDetail();
            query.IsContinueToLive = IsContinueToLive;
            query.OrderStatus = orderStatus;
            query.HouseTypeId = houseTypeId;
            query.Data = data;
            query.OrderTimeType = orderTimeType;
            query.OrderTimeBegin = orderTimeBegin;
            query.OrderTimeEnd = orderTimeEnd;
            query.PageNumber = pageNumber;
            query.PageSize = pageSize;

            ResultDto<PageListDto<ListOrderDetailDto>> result = _orderAppService.GetPagedList(query);

            return result;
        }

        /// <summary>
        /// 查询所有订单下的房型
        /// </summary>
        /// <returns></returns>
        [HttpGet, Route("[action]")]
        public ResultDto<List<SelectHouseTypeDto>> FindAllOrdersHouseTypes()
        {
            ResultDto<List<SelectHouseTypeDto>> result = _orderAppService.GetAllOrdersHouseTypes();

            return result;
        }
    }
}
